﻿using System.ComponentModel;
using System.Data.Linq.Mapping;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;

namespace DnD.Model
{
    [Table]
    [InheritanceMapping(Code = "C", Type = typeof(Card))]
    [InheritanceMapping(Code = "D", Type = typeof(Deck))]
    [InheritanceMapping(Code = "A", Type = typeof(DnDAction))]
    [InheritanceMapping(Code = "G", Type = typeof(GameItem), IsDefault=true)]
    public class GameItem : INotifyPropertyChanged
    {
        protected int _id;
        protected int _onlineID;
        protected string _name;
        protected string _author;
        protected string _despcription;
        protected string _pictureURL;
        protected double _rate;
        protected int _rateCount;
        protected bool _local;
        protected string _localPictureName;
        protected bool _isPictureModified;


        public GameItem()
        {
            Rate = 0;
            RateCount = 0;
        }

        [Column(IsDiscriminator = true)]
        public string DiscKey;

        [Column(IsDbGenerated = true, IsPrimaryKey = true)]
        public int Id
        {
            get { return _id; }
            set
            {
                _id = value;
                OnPropertyChanged();
            }
        }

        [Column]
        public int OnlineID
        {
            get { return _onlineID; }
            set
            {
                _onlineID = value;
                OnPropertyChanged();
            }
        }


        [Column]
        public string Name
        {
            get { return _name; }
            set
            {
                _name = value;
                OnPropertyChanged();
            }
        }

        [Column]
        public string Description
        {
            get { return _despcription; }
            set
            {
                _despcription = value;
                OnPropertyChanged();
            }
        }

        [Column]
        public string Author
        {
            get { return _author; }
            set
            {
                _author = value;
                OnPropertyChanged();
            }
        }

        [Column]
        public string PictureURL
        {
            get { return _pictureURL; }
            set
            {
                _pictureURL = value;
                OnPropertyChanged();
            }
        }

        [Column]
        public double Rate
        {
            get { return _rate; }
            set
            {
                _rate = value;
                OnPropertyChanged();
            }
        }

        [Column]
        public int RateCount
        {
            get { return _rateCount; }
            set
            {
                _rateCount = value;
                OnPropertyChanged();
            }
        }

        [Column]
        public bool Local
        {
            get { return _local; }
            set
            {
                _local = value;
                OnPropertyChanged();
            }
        }

        [Column]
        public string LocalPictureName
        {
            get { return _localPictureName; }
            set
            {
                _localPictureName = value;
                OnPropertyChanged();
            }
        }

        [Column]
        public bool IsPictureModified
        {
            get { return _isPictureModified; }
            set
            {
                _isPictureModified = value;
                OnPropertyChanged();
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
                handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
  
}
